package com.lvtongka.app.ui.setting

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.lvtongka.app.base.BaseViewModel
import com.lvtongka.app.common.bean.AgreementItem
import com.lvtongka.app.common.bean.AgreementRequest
import com.lvtongka.app.common.bean.AgreementResponse
import com.lvtongka.app.http.HttpCallBack
import com.lvtongka.app.http.OkhttpUtils
import com.lvtongka.app.http.common.UrlConstants

class SettingViewModel : BaseViewModel() {
    private val _agreementList = MutableLiveData<List<AgreementItem>>()
    val agreementList:LiveData<List<AgreementItem>> = _agreementList

    fun getAgreementList() {
        val request = AgreementRequest("", "")
        OkhttpUtils.getInstance()
            .postRequest(Gson().toJson(request), UrlConstants.API_USE_POLICY, object :
                HttpCallBack {
                override fun onError(errorLog: String) {
                    _error.postValue(errorLog)
                }

                override fun onSuccess(result: String) {
                    val agreementResponse = Gson().fromJson(result, AgreementResponse::class.java)
                    _agreementList.postValue(agreementResponse.list)
                }
            })
    }
}